<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<button>防抖按钮</button>

	<script>
		const btn = document.querySelector('button');


		function fn() {
			console.log(new Date().getTime())
		}
		// btn.onclick = fn


		function debounce(fn, wait = 2000) {
			let timeout;
			return function () {
				const args = arguments;
				clearTimeout(timeout)
				timeout = setTimeout(() => {
					fn.apply(this, args)
				}, wait);
			}
		}

		btn.onclick = debounce(fn)
	</script>
</body>

</html>